package untils

import (
    "github.com/mojocn/base64Captcha"
    "image/color"
)


type Captcha struct {
    Id string
    Bs64 string
    Code int
}

var store = base64Captcha.DefaultMemStore

/**
 * 生成验证码
 */
func GetCaptcha() (id string,base64 string,err error) {

    bgcolor := color.RGBA{0,0,0,0,}
    fonts := []string{"wqy-microhei.ttc"}
    driver := base64Captcha.NewDriverMath(50,140,0,0,&bgcolor,fonts)

    captcha := base64Captcha.NewCaptcha(driver,store)

    // 生成验证码
    id, base64, err = captcha.Generate()
    return id,base64,err

}

/**
 *  验证码验证函数
 */
func VerityCaptcha(id string,ret_captcha string) bool{
    return store.Verify(id,ret_captcha,true)
}